<template>
    <div class='dialog'>
        <div class='newAdd dialog-con updateCompanyInfo'>
          <split-vertical title="修改公司信息"></split-vertical>
            <div class='companynameList'>
                <el-form :model="ruleForm"  ref="ruleForm" label-width="110px"  class="demo-ruleForm"  inline label-position="right">
                    <el-form-item label="公司名称" prop="companyName">
                        <el-input v-model="add.companyName"></el-input>
                    </el-form-item>
                    <el-form-item label="公司编码" prop="companyCode">
                        <el-input v-model="add.companyCode"></el-input>
                    </el-form-item>
                    <el-form-item label="法人代表" prop="companyDeputy">
                        <el-input v-model="add.companyDeputy"></el-input>
                    </el-form-item>
                    <el-form-item label="我司对公账户名" prop="companyAccountName">
                        <el-input v-model="add.companyAccountName"></el-input>
                    </el-form-item>
                    <el-form-item label="账号" prop="accountNo">
                        <el-input v-model="add.accountNo"></el-input>
                    </el-form-item>
                    <el-form-item label="开户行" prop="accountBank">
                        <el-input v-model="add.accountBank"></el-input>
                    </el-form-item>
                    <el-form-item label="税号" prop="tax">
                        <el-input v-model="add.tax"></el-input>
                    </el-form-item>
                     <el-form-item label="公司电话" prop="companyMobile">
                        <el-input v-model="add.companyMobile"></el-input>
                    </el-form-item>
                     <el-form-item label="客服电话" prop="artificialMobile">
                        <el-input v-model="add.artificialMobile"></el-input>
                    </el-form-item>
                    <el-form-item class="btn">
                        <el-button @click="submitForm('ruleForm')" type="primary" size="medium">提交</el-button>
                        <el-button @click="cancel"  size="medium">取消</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</template>
<script>
import api from 'js/service'
import SplitVertical from "components/common/SplitVertical"
import {localStorage} from 'js/localStorage'
export default {
    inject:['reload'],
    components:{
      SplitVertical
    },
    data(){
        return{
           newCompany:[
               {name:'公司名称',val:'必输项'},
               {name:'法人代表',val:'必输项'},
               {name:'我司对公账户名',val:'必输项'},
               {name:'账号',val:'必输项'}
           ],
            pageIndex:1,
            pageSize:10,
            userId:'',
            ruleForm:{
                companyCode:'',//  公司编码
                companyName:'',//  公司名称
                companyDeputy:'',//公司法人代表
                companyAccountName:'',//我司对公账户
                accountBank:'',//开户行
                accountNo:'',//开户行账户
                companyMobile:'',
                artificialMobile:'',
                tax:'',
            }
        }
    },
    props:{
        add:{
            type:Object,
            default:{}
        }
    },
    created(){
        this.userId=localStorage.get('userID')
    },
    methods:{
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
            if (valid) {
                this.confirm()
            } else {
                return false;
            }
            });
        },
        confirm(){
            let parmas={
                pageIndex:this.pageIndex,
                pageSize:this.pageSize,
                companyCode:this.add.companyCode,
                companyName:this.add.companyName,
                companyDeputy:this.add.companyDeputy,
                companyAccountName:this.add.companyAccountName,
                accountBank:this.add.accountBank,
                accountNo:this.add.accountNo,
                tax:this.add.tax,
                id:this.add.id,
                userId:this.userId,
                companyMobile:this.add.companyMobile,
                artificialMobile:this.add.artificialMobile
            }
            let success=data=>{
                if(data.code=='OK'){
                    this.$message.success('保存成功')
                    this.$emit('closeDialog')
                    this.reload()
                }else{
                    this.$message.error(data.msg)
                }
            }
            api.addCompanyUpdate(parmas,success)
        },
        cancel(){
            this.$emit('closeDialog')
        },
    }
}
</script>
<style lang="scss" scoped>
    .updateCompanyInfo{
        width:700px;
        height:450px;

        .companynameList{
            margin-left:5px;
            .el-input{
              width:220px;
            }
        }
        .btn{
            position: relative;
            left:20%;
            top:30%;
            margin-top: 35px;
        }
    }
</style>

